package kizzo.geometry 
{
	import flash.geom.Point;
	import flash.geom.Vector3D;
	import kizzo.game.Game;
	import org.cove.ape.Vector;
	/**
	 * ...
	 * @author KiZZo
	 */
	public class TileCoord3D 
	{		
		public static var OFFSET:uint;
		public static var TILE:Number;		
		
		public var x:int;
		public var y:int;
		public var z:int;
		public var id:int;
		
		public static var NW_VECTOR:TileCoord3D;
		public static var SW_VECTOR:TileCoord3D;
		public static var NE_VECTOR:TileCoord3D;
		public static var SE_VECTOR:TileCoord3D;					
		
		public function TileCoord3D(x:int, y:int, z:int, id:int=0) 
		{
			this.x = x;
			this.y = y;
			this.z = z;
			this.id = id;
		}
		
		
		public static function init():void
		{
			TileCoord3D.OFFSET = Game.ARRAY_OFFSET;			
			TileCoord3D.TILE = Game.TILE;		
			
			NW_VECTOR = new TileCoord3D(1, 0, 0);
			SW_VECTOR = new TileCoord3D(0, 0, 1);
			NE_VECTOR = new TileCoord3D(0, 0, -1);
			SE_VECTOR = new TileCoord3D(-1, 0, 0);			
		}
		
		public static function set_vectors():void
		{
		}
		
				
		public function add(v:TileCoord3D):TileCoord3D
		{
			return new TileCoord3D(this.x + v.x, this.y + v.y, this.z + v.z);
		}
		
		
		public function get x_o():int
		{
			return this.x + OFFSET;			
		}
		
		public function get y_o():int
		{
			return this.y + OFFSET;			
		}		
		
		public function get z_o():int
		{
			return this.z + OFFSET;			
		}
		
		
		public function get x_m():Number
		{
			return this.x * TileCoord3D.TILE;			
		}
		
		public function get y_m():Number
		{
			return this.y * TileCoord3D.TILE;			
		}		
		
		public function get z_m():Number
		{
			return this.z * TileCoord3D.TILE;			
		}	
		
		
		public function to_2D():Point
		{
			var dir_vector:Vector3D = Main.get_instance().view_3D.project(new Vector3D(this.x,this.y,this.z));
			var origin_vector:Vector3D = Main.get_instance().view_3D.project(new Vector3D(0,0,0));			
			dir_vector = dir_vector.subtract(origin_vector);
			return new Point(dir_vector.x, dir_vector.y);	
		}		
		
		
		public function to_string():String
		{
			return ("x:" + this.x + " y:" + this.y +" z:" + this.z + " id:" + this.id);
		}
		
	}

}